﻿@{
    Layout = null;
    ViewBag.Title = "模块管理——公路工程建设项目造价全过程管理系统";
}
@using KingRoad.EPM.Common.Helper
<script type="text/javascript">
    $(function () {
        //计算分栏高度
        var contentHeight = $("#tabContent").innerHeight() - $(".panelBar",navTab.getCurrentPanel()).outerHeight();
        $("#mainContent_permission_SystemCode_index").height(contentHeight);
        
    });
    //树
    var zNodes_permission_SystemCode_index = [];

    var zTree_permission_SystemCode_index;
    var setting_permission_SystemCode_index;
    //全局的href
    var href__permission_SystemCode_index = "/Permission/SystemCode";
    setting_permission_SystemCode_index = {
        checkable: false,
        async: true,
        isSimpleData: true,
        editable: true,
        edit_removeBtn: false,
        edit_renameBtn: false,
        dragCopy: true,
        dragMove: true,
        asyncUrl: "/Permission/SystemCode/GetzTreeDB",  //获取节点数据的URL地址
        //asyncDataFilter: ajaxDataFilter,
        nameCol: "SYSTEMCODE_NAME",
        open: false,
        treeNodeKey: "SYSTEMCODE_ID",
        treeNodeParentKey: "SYSTEMCODE_PARENTID",
        callback: {
            //             beforeAsync: zTreeBeforeAsync,
            asyncSuccess: zTreeOnAsyncSuccess_permission_SystemCode_index,
            //             asyncError: zTreeOnAsyncError,
            click: zTreeOnClick_permission_SystemCode_index
        }
    };

    function zTreeOnAsyncSuccess_permission_SystemCode_index(event, treeId, treeNode, msg) {
        //异步成功
    }
    //树的单击事件
    function zTreeOnClick_permission_SystemCode_index(event, treeId, treeNode) {

        $("#rightDetail_permission_SystemCode_index").load("/Permission/SystemCode/Details/" + treeNode.SYSTEMCODE_ID, null, function () {
            //添加
            var addUrl_permission_SystemCode_index = href__permission_SystemCode_index + "/Create/" + treeNode.SYSTEMCODE_ID;
            $("#add_permission_SystemCode_index").attr("href", addUrl_permission_SystemCode_index);
            //更新
            var editUrl_permission_SystemCode_index = href__permission_SystemCode_index + "/EditSystemCode/" + treeNode.SYSTEMCODE_ID;
            $("#edit_permission_SystemCode_index").attr("href", editUrl_permission_SystemCode_index);
        });
    }

    $(document).ready(function () {
        refreshTree();
        //模块删除操作
        $("#del_permission_SystemCode_index").click(function () {
            if (zTree_permission_SystemCode_index.getSelectedNode()) {
                alertMsg.confirm("您确定要删除吗？", {
                    okCall: function () {
                        $.post("/Permission/SystemCode/Delete", { "Id": zTree_permission_SystemCode_index.getSelectedNode().SYSTEMCODE_ID }, dialogdel_permission_SystemCode_index, "json");
                    }
                });
            } else {
                alertMsg.error("请先选择要删除的项！");
                return false;
            }
        });
    });

    function refreshTree() {
        zTree_permission_SystemCode_index = $("#treeSystemCode_permission_SystemCode_index").zTree(setting_permission_SystemCode_index, zNodes_permission_SystemCode_index);
    }
    function dialogAdded_Permission_SystemCode(json) {
        //提交回调
        //1 接收参数 2 判断成功与否 3 根据返回的数据在树上新增节点
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //添加成功
            if (json.callbackType == "Create") {
                var newParentNode = zTree_permission_SystemCode_index.getNodeByParam("SYSTEMCODE_ID", json.data.SYSTEMCODE_PARENTID);
                zTree_permission_SystemCode_index.addNodes(newParentNode, json.data);
            } else if (json.callbackType == "Edit") {
                //更新成功
                var selectedNode = zTree_permission_SystemCode_index.getSelectedNode();
                if (selectedNode.SYSTEMCODE_PARENTID == json.data.SYSTEMCODE_PARENTID) {//更新当前选中的节点
                    selectedNode.SYSTEMCODE_NAME = json.data.SYSTEMCODE_NAME;
                    zTree_permission_SystemCode_index.updateNode(selectedNode, true);
                }
                var newNode = zTree_permission_SystemCode_index.getNodeByParam("SYSTEMCODE_ID", json.data.SYSTEMCODE_ID);
                zTree_permission_SystemCode_index.selectNode(newNode);
                $("#rightDetail_permission_SystemCode_index").load("/Permission/SystemCode/Details/" + json.data.SYSTEMCODE_ID);
            }
            $.pdialog.closeCurrent();
        }
    }
    //模块删除回调函数
    function dialogdel_permission_SystemCode_index(json) {
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //删除成功
            var selectedNode = zTree_permission_SystemCode_index.getSelectedNode();
            zTree_permission_SystemCode_index.removeNode(selectedNode, true);
            //当前节点删除后添加、编辑需要初始化
            $("#add_permission_SystemCode_index").attr("href", href__permission_SystemCode_index + "/Create/0");
            $("#edit_permission_SystemCode_index").attr("href", href__permission_SystemCode_index + "/Edit/{sid_user}");
        }
    }
</script>
<div class="page">
    @*顶部按钮*@
    <div class="panelBar">
        <ul class="toolBar">
            <li>@Html.PermissionButton("Permission.SystemCode.Create", "add_permission_SystemCode_index", "add", "/Permission/SystemCode/Create/{sid_user}", "new_edit", "dialog", "添加", "true", "400", "340", "添加")</li>
            <li>@Html.PermissionButton("Permission.SystemCode.Edit", "edit_permission_SystemCode_index", "edit", "/Permission/SystemCode/Edit/{sid_user}", "new_edit", "dialog", "编辑", "true", "400", "340", "编辑")</li>
            <li>@Html.PermissionButton("Permission.SystemCode.Delete", "del_permission_SystemCode_index", "delete", "javascript:void(0);", "", "", "", "", "删除")</li>
        </ul>
    </div>
    <div id="mainContent_permission_SystemCode_index">
        <div id="LeftPane" class="leftPanel">
            @*菜单树*@
            <ul id="treeSystemCode_permission_SystemCode_index" class="ztree">
            </ul>
        </div>
        <div id="RightPane_permission_SystemCode_index" class="rightPanel">
            @*表单内容*@
            <div id="rightDetail_permission_SystemCode_index">
            </div>
        </div>
    </div>
</div>
